package initEffect 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import com.greensock.TweenLite;
	import flash.events.MouseEvent;
	/**
	 * 淡入進場效果
	 * @author cain in liontravel 2010
	 */
	public class InitEffect extends MovieClip 
	{
		private var _s:Number; //淡入出時間
		/**
		 * 淡入進場效果
		 * @param	_t 淡入時間
		 */
		public function InitEffect(_t:Number = .5) 
		{ 
			_s = _t;
			setup();
		}
		/**
		 * 移除自己
		 * @param	_t
		 */
		public function remove(_t:Number = .5):void 
		{
			TweenLite.to(this, _t, { alpha:0 , onComplete:remove_me } );
		}
		/**
		 * 點我退出
		 * @param	_t 淡出時間
		 */
		public function click_remove(_t:Number = .5):void 
		{
			_s = _t;
			buttonMode = true;
			addEventListener(MouseEvent.CLICK, onCLIKC);
		}
		private var readme_text:ReadMe; //說明文字
		/**
		 * 說明文字
		 * @param	_str 內容
		 */
		public function readme(_str:String):void 
		{
			readme_text = new ReadMe(_str);
			addEventListener(MouseEvent.ROLL_OVER, onROLL_OVER);
			addEventListener(MouseEvent.ROLL_OUT, onROLL_OUT);
		}
		
		private function onROLL_OUT(e:MouseEvent):void 
		{
			readme_text.stopDrag();
			removeChild(readme_text);
		}
		
		private function onROLL_OVER(e:MouseEvent):void 
		{
			readme_text.x = mouseX + 10;
			readme_text.y = mouseY - 5;
			addChild(readme_text);
			readme_text.startDrag();
		}
		private function onCLIKC(e:MouseEvent):void 
		{
			removeEventListener(MouseEvent.CLICK, onCLIKC);
			onROLL_OVER(null);
			buttonMode = false;
			remove(_s);
		}
		private function remove_me():void
		{
			try 
			{
				parent.removeChild(this);
			}catch (err:Error)
			{
				
			}
		}
		private function setup():void
		{
			addEventListener(Event.ADDED_TO_STAGE, onADDED_TO_STAGE);
		}
		private function onADDED_TO_STAGE(e:Event):void 
		{
			addEventListener(Event.REMOVED_FROM_STAGE, onREMOVED_FROM_STAGE);
			init();
		}
		private function init():void
		{
			movieing();//動畫
			addEventListeners();
		}
		
		private function movieing():void //動畫
		{
			TweenLite.from(this, _s, { alpha:0 } );
		}
		
		private function addEventListeners():void
		{
			
		}
		private function removeEventListeners():void
		{
			removeEventListener(MouseEvent.CLICK, onCLIKC);
			removeEventListener(MouseEvent.ROLL_OVER, onROLL_OVER);
			removeEventListener(MouseEvent.ROLL_OUT, onROLL_OUT);
		}
		private function onREMOVED_FROM_STAGE(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, onADDED_TO_STAGE);
			removeEventListener(Event.REMOVED_FROM_STAGE, onREMOVED_FROM_STAGE);
			removeEventListeners();
			readme_text = null;
		}
	}
	
}